package thread.objects;

import lombok.SneakyThrows;

public class MoreLock {
    public static void main(String[] args) {
        Object obj1 = new Object();
        Object obj2 = new Object();

        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (obj1){
                    obj1.wait();
                    System.out.println("obj1 lock");
                    synchronized (obj2){
                        obj2.wait();
                        System.out.println("obj2 lock");
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj1){
                    obj1.notify();
                    System.out.println("notify obj1");
                    synchronized (obj2){
                        obj2.notify();
                        System.out.println("notify obj2");
                    }
                }
            }
        }).start();
    }
}
